{extend name="public/base"}

{block name="x-body"}
<style>
  #box {
    border: 1px solid #2cbca3;

    padding: 0 20px;

    position: relative;
  }

  #box #editOrder {
    position: absolute;
    right: 0;
    top: 0;

    z-index: 99;
  }

  #box .layui-table {
    border-bottom: 1px solid #e5e5e5;
  }

  #box th {
    background: white;
    color: #656565;
    font-weight: bold;
  }

  #box td div {
    width: 100px;

    display: inline-block;

    color: #999;
    text-align: right;
  }

  #box td span {
    color: black;
  }

  .box_table thead th {
    background: #f2f2f2 !important;

    font-weight: normal;
    font-size: 12px;
    text-align: center;
  }

  .box_table tbody td {
    font-size: 12px;
    text-align: center;
  }

  .layui-table td, .layui-table th {
    font-size: 13px;
  }
</style>
<div class="x-body">
  <div class="layui-row">
    <div class="layui-col-md8 layui-col-md-offset2" id="box">
      {if $order.order_status == 0 && $order.pay_status == 0 && $order.shipping_status == 0}
      <button class="layui-btn layui-btn" onclick="load_url('{:url(\'orders/order_form\', [\'id\' => $order.id])}')" id="editOrder"><i class="layui-icon">&#xe642;</i>修改订单</button>
      {/if}
      <div class="layui-row">

        <!-- 基本信息 -->
        <table class="layui-table" lay-skin="nob">

          <colgroup>
            <col width="33%">
            <col width="33%">
            <col width="33%">
          </colgroup>
          <thead>
          <tr>
            <th colspan="3">基本信息</th>
          </tr>
          </thead>
          <tbody>
          <tr>
            <td>
              <div>订单 ID：</div>
              <span>{$order.id}</span>
            </td>
            <td>
              <div>订单编号：</div>
              <span>{$order.order_sn}</span>
            </td>
            <td>
              <div>会员：</div>
              <span>{$order.username}</span>
            </td>
          </tr>

          <tr>
            <td>
              <div>E-Mail：</div>
              <span>{$order.email ? $order.email : '无'}</span>
            </td>
            <td>
              <div>电话：</div>
              <span>{$order.u_mobile ? $order.u_mobile : '无'}</span>
            </td>
            <td>
              <div>应付{$order.integral ? '积分' : '金额'}：</div>
              <span>{$order.integral ? $order.integral : $order.order_amount}</span>
            </td>
          </tr>

          <tr>
            <td>
              <div>订单状态：</div>
              <span>
                      {switch name="order.order_status"}
                        {case value="0"}未确定{/case}
                        {case value="1"}已确定{/case}
                        {case value="2"}已收货{/case}
                        {case value="3"}已取消{/case}
                        {case value="4"}已完成{/case}
                        {case value="5"}已作废{/case}
                      {/switch}
                      /
                      {$order.pay_status == 1 ? '已支付' : '未支付'}
                      /
                      {if $order.shipping_status == 1}
                        已发货
                      {elseif $order.shipping_status == 2}
                        部分发货
                      {else /}
                        未发货
                      {/if}
                    </span>
            </td>
            <td>
              <div>下单时间：</div>
              <span>{$order.add_time|date="Y-m-d H:i"}</span>
            </td>
            <td>
              <div>支付时间：</div>
              <span>{if $order.pay_time}{$order.pay_time|date="Y-m-d H:i"}{else /}无{/if}</span>
            </td>
          </tr>

          <tr>
            <td>
              <div>支付方式：</div>
              <span>{$order.pay_name ? $order.pay_name : '无'}</span>
            </td>
            <td>
              <div>发票抬头：</div>
              <span>{$order.invoice.invoice_title == 1 ? '公司' : '个人'}</span>
            </td>
            <td>
              <div>纳税人识别号：</div>
              <span>{$order.invoice ? $order.invoice.taxpayer : '无'}</span>
            </td>
          </tr>
          </tbody>
        </table>

        <!-- 发票信息 -->
        <table class="layui-table" lay-skin="nob">
          <colgroup>
            <col width="33%">
            <col width="33%">
            <col width="33%">
          </colgroup>
          <thead>
          <tr>
            <th colspan="3">发票信息</th>
          </tr>
          </thead>
          <tbody>
          <tr>
            <td>
              <div>发票抬头：</div>
              <span>{$order.invoice.invoice_title == 1 ? '公司' : '个人'}</span>
            </td>
            <td>
              <div>发票类型：</div>
              <span>商品发票</span>
            </td>
            <td>
              <div>纳税人类型：</div>
              <span>{$order.invoice.taxpayer_type == 0 ? '增值税' : '非增值税'}</span>
            </td>
          </tr>
          <tr>
            <td>
              <div>单位名称：</div>
              <span>{$order.invoice.unit_name ? $order.invoice.unit_name : '无'}</span>
            </td>
            <td colspan="2">
              <div>纳税人识别号：</div>
              <span>{$order.invoice.taxpayer ? $order.invoice.taxpayer : '无'}</span>
            </td>
          </tr>
          </tbody>
        </table>

        <!-- 商品信息 -->
        <table class="layui-table" lay-skin="nob">
          <colgroup>
            <col width="33%">
            <col width="33%">
            <col width="33%">
          </colgroup>
          <thead>
          <tr>
            <th colspan="3">商品信息</th>
          </tr>
          </thead>
          <tbody>
          <tr>
            <td>
              <table class="layui-table box_table" lay-skin="line" style="margin: 0;">
                <thead>
                <tr>
                  <th>商品编号</th>
                  <th>商品</th>
                  <th>数量</th>
                  <th>单品价格</th>
                  {if !$order.integral}
                  <th>会员折扣价</th>
                  {/if}
                  <th>单品小计</th>
                </tr>
                </thead>
                <tbody>
                {volist name="$order.goods" id="v"}
                <tr>
                  <td>{$v.goods_sn}</td>
                  <td>
                    <img src="{:config('imgRoute')}{$v.original_img}" style="width: 30px; height: 30px;" alt="">
                    {$v.goods_name}
                  </td>
                  <td>{$v.goods_num}</td>
                  <td>{$v.goods_integral ? $v.goods_integral : $v.goods_price}</td>
                  {if !$v.goods_integral}
                  <td>{$v.member_goods_price}</td>
                  {/if}
                  <td>{$v.goods_integral ? $v.goods_integral : $v.member_goods_price * $v.goods_num}</td>
                </tr>
                {/volist}
                </tbody>
              </table>
            </td>
          </tr>
          <tr>
            <td colspan="7" style="text-align: right;">
              订单总额：{if !$order.integral}￥{$order.total_amount}{else /}{$order.integral}{/if}
            </td>
          </tr>
          </tbody>
        </table>

        <!-- 费用信息 -->
        <table class="layui-table" lay-skin="nob">
          <colgroup>
            <col width="33%">
            <col width="33%">
            <col width="33%">
          </colgroup>
          <thead>
          <tr>
            <th colspan="3">
              费用信息
              {if $order.order_status == 0 && $order.pay_status == 0 && $order.shipping_status == 0}
              <button class="layui-btn layui-btn-normal layui-btn-xs"  onclick="load_url('{:url(\'orders/order_cost\', [\'id\' => $order.id])}')" ><i class="layui-icon">&#xe642;</i>修改费用</button>
              {/if}
            </th>
          </tr>
          </thead>
          <tbody>
          <tr>
            <td>
              <div>小计：</div>
              <span>{$order.integral ? $order.integral : $v.goods_price}</span>
            </td>
            <td>
              <div>运费：</div>
              <span>+{$order.shipping_price}</span>
            </td>
            <td>
              <div>优惠券抵扣：</div>
              <span>-{$order.coupon_price}</span>
            </td>
          </tr>

          <tr>
            <td>
              <div>价格调整：</div>
              <span>{$order.discount >= 0 ? '+' : '-'}{$order.discount}</span>
            </td>
            <td colspan="2">
              <div>应付：</div>
              <span>{$order.order_amount}</span>
            </td>
          </tr>
          </tbody>
        </table>

        <!-- 操作信息 -->
        <table class="layui-table" lay-skin="nob">
          <colgroup>
            <col width="33%">
            <col width="33%">
            <col width="33%">
          </colgroup>
          <thead>
          <tr>
            <th colspan="3">操作信息</th>
          </tr>
          </thead>
          <tbody>
          <tr>
            <td colspan="3">
                {if $order.invoice.status == 1}
              <form class="layui-form">
                <input type="hidden" name="status_desc" value="">
                <input type="hidden" name="order_id" value="{$order.id}">
                <input type="hidden" name="action_user" value="{$Think.session.user.id}">
                <div style="width: 100%;">
                  <div style="float: left;">操作备注：</div>
                  <textarea placeholder="请输入操作备注" id="action_note" name="action_note" class="layui-textarea" style="width: 60%; float: left; margin: 0 0 6px 4px;"></textarea>
                </div>

                <div>可执行操作：</div>
                <button class="layui-btn" lay-filter="add1" lay-submit="" data-name="invoice_status" data-val="3">确定开票</button>
                {elseif $order.invoice.status == 3/}
                <button class="layui-btn layui-btn-disabled">已开票</button>
                {elseif $order.invoice.status == 0/}
                <button class="layui-btn layui-btn-disabled">不开发票</button>
                {elseif $order.invoice.status == 2/}
                <button class="layui-btn layui-btn-disabled">暂不开票</button>
                {/if}
              </form>
            </td>
          </tr>
          </tbody>
        </table>


      </div>
    </div>
  </div>
</div>

<script>
    $(function (){
        layui.use('form', function(){
            var form = layui.form;

            form.on('submit(add1)', function(data){
                let url = "{:url('finance/invoice_cat')}";
                let json = data.field;
                let name = data.elem.dataset.name;
                let code = data.elem.dataset.val;

                json.pay_status = '{$order.pay_status}';
                json.order_status = '{$order.order_status}';
                json.shipping_status = '{$order.shipping_status}';

                json[name] = code;
                json.status_desc= '确认开票';

                data.field.__token__ = $("input[name='__token__']",top.window.document).val();
                data.field.invoice_id = '{$order.invoice.id}';

                $.post(url, data.field, function(res){
                    if(res.code == 0){
                        dialog(res.msg, false, 0, function (){
                            $("input[name='__token__']",top.window.document).val(res.data.token);
                        });
                    }else if(res.code == 1){
                        dialog(res.msg, res.url, 0, function (){
                            $("input[name='__token__']",top.window.document).val(res.data.token);
                        }, true);
                    }
                }, 'json');

                return false;
            });
        });
    })

</script>
{/block}